import axios from "axios";
export default {
  props:{
    playerId:{
      type:Number
    },
    season:{
      type:String,
      default(){
        return '2019赛季'
      }
    }
  },
  watch:{
    season:{
      handler(newSeasonId){
        this.getData(parseInt(newSeasonId),this.playerId)
      },
      immediate:true
    },
    playerId:{
      handler(newPlayerId){
        this.getData(parseInt(this.season),newPlayerId)
      },
      immediate:true
    },
  },
  data(){
    return {
      leftData:[],
      rightData:[],
      loading:true,
    }
  },
  methods:{
    //设置表格行的样式
    tableRowStyle({row,rowIndex}){
      return {
        'text-align': 'center',
        'font-size': '18px',
        'font-weight': 'bold',
        'background-color':'#f1f6f9'
      }
    },

    //设置表头的样式
    tableHeaderColor({row,column,rowIndex,columnIndex}){
      if(columnIndex === 0 ){
        return {
          'font-size':'24px',
          'font-weight':'bold',
          'color':'black',
          'background-color':'#f1f6f9'
        }
      } else {
        return {
          'font-size':'18px',
          'font-weight':'bold',
          'color':'#656F73',
          'background-color':'#f1f6f9'
        }
      }
    },

    //射门助攻  合并单元格
    shootAssistHead({row,column,rowIndex,columnIndex}){
      if(rowIndex === 0 && columnIndex===0){
        return {
          'font-size':'24px',
          'font-weight':'bold',
          'color':'black',
          'text-align':'left',
          'background-color':'#f1f6f9'
        }
      }
      if (rowIndex === 1) {      //合并最开始的两个头部单元格
        return { display: 'none' }
      }
      return {
        'font-size':'18px',
        'font-weight':'bold',
        'color':'#656F73',
        'text-align':'center',
        'background-color':'#f1f6f9'
      }
    },

    //设置单元格的样式(if里面可以多写几个判断实现多个单元格样式)
    //左侧进球table的设置当前球员所在行的背景颜色
    goalCellStyle({row,column,rowIndex,columnIndex}){
      const leftDataIndex = this.leftData.findIndex(item=>item.playerId===this.playerId);
      if(columnIndex === 0 || rowIndex === leftDataIndex){
        return {'background-color':'rgba(1, 83, 139, 0.2)'}
      }
    },
    //右侧射门table的设置当前球员所在行的背景颜色
    shootCellStyle({row,column,rowIndex,columnIndex}){
      const rightDataIndex = this.rightData.findIndex(item=>item.playerId===this.playerId);
      if(columnIndex === 0 || rowIndex === rightDataIndex){
        return {'background-color':'rgba(1, 83, 139, 0.2)'}
      }
    },

    //获取数据
    async getData(seasonId,playerId){
      this.loading = true;
      const {data} = await axios.get(`http://8.141.159.127:3000/api/v1/playerfeatures/${this.type}/6/${seasonId}/${playerId}`)
      this.leftData = data[Object.keys(data)[0]];
      this.rightData = data[Object.keys(data)[1]];
      this.loading = false;
    },
    //点击球员进入具体球员
    enterPlayer(playerId){
      this.$router.push({ name: 'singlePlayer', params:{playerId}})
    }
  },
}